package com.yxq.mdt.app.modules.logistics.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.order.bean.ExpressBean;
import com.yxq.mdt.app.modules.order.bean.OrderConfirmBean;
import com.yxq.mdt.app.modules.order.bean.OrderDetailBean;
import com.yxq.mdt.app.modules.order.bean.OrderListBean;
import com.yxq.mdt.app.modules.order.bean.OrderPayResultBalanceBean;
import com.yxq.mdt.app.modules.order.bean.OrderPayResultWxBean;
import com.yxq.mdt.app.modules.order.bean.OrderSubmitResult;
import com.yxq.mdt.app.modules.order.model.OrderModel;
import com.yxq.mdt.app.modules.order.prestener.IOrderContract;
import com.yxq.mdt.app.modules.order.prestener.OrderPresenter;
import com.yxq.mdt.app.utils.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author L
 * @time
 * @describe 物流
 */
public class LogisticsActivity extends BaseActivity<OrderPresenter> implements IOrderContract.View {


    @BindView(R.id.order_confirm_goods_list_iv_img)
    ImageView orderConfirmGoodsListIvImg;
    @BindView(R.id.cart_tv_name_log)
    TextView cartTvNameLog;
    @BindView(R.id.cart_tv_attr_name)
    TextView cartTvAttrName;
    @BindView(R.id.order_tv_copy)
    TextView orderTvCopy;
    @BindView(R.id.cart_tv_price_name)
    TextView cartTvPriceName;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    LogisticsAdapter logisticsAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_logistics;
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter = new OrderPresenter(this, new OrderModel());
        showLoadingDialog();
        mPresenter.express(getIntent().getStringExtra("orderId"), getIntent().getIntExtra("orderType", 1) + "");
    }

    @OnClick(R.id.order_tv_copy)
    public void onViewClicked() {
    }

    @Override
    public void onLoadSuccess(OrderConfirmBean orderConfirmBean) {

    }

    @Override
    public void onLoadFailed(String err) {

    }

    @Override
    public void onLoadListSuccess(OrderListBean orderListBean) {

    }

    @Override
    public void onLoadListFailed(String err) {

    }

    @Override
    public void onSubmitSuccess(OrderSubmitResult orderSubmitResult) {

    }

    @Override
    public void onSubmitFailed(String err) {

    }

    @Override
    public void onPayBalanceSuccess(OrderPayResultBalanceBean orderPayResultBalanceBean) {

    }

    @Override
    public void onPayBalanceFailed(String err) {

    }

    @Override
    public void onPayWxSuccess(OrderPayResultWxBean orderPayResultWxBean) {

    }

    @Override
    public void onPayWxFailed(String err) {

    }

    @Override
    public void onDetailSuccess(OrderDetailBean orderDetailBean) {

    }

    @Override
    public void onDetailFailed(String err) {

    }

    @Override
    public void onExpressSuccess(ExpressBean expressBean) {
        hideLoadingDialog();
        bindUI(expressBean);

    }

    /**
     * 设置数据
     *
     * @param expressBean
     */
    private void bindUI(ExpressBean expressBean) {
        if (expressBean == null) {
            return;
        }
        GlideHelper.setLoadRoundImage(mActivity, expressBean.getGoodsPic(), R.color.gray, orderConfirmGoodsListIvImg);
        cartTvNameLog.setText(expressBean.getExpress());
        cartTvAttrName.setText(expressBean.getExpressNo());
        cartTvPriceName.setText(expressBean.getStatusText());
        orderTvCopy.setOnClickListener(view -> {
            if (TextUtils.isEmpty(expressBean.getExpressNo())) {
                ToastUtils.showShort("没有物流单号");
                return;
            }
            StringUtils.copy(mActivity, expressBean.getExpressNo());
            ToastUtils.showShort("复制成功");
        });
        logisticsAdapter = new LogisticsAdapter(R.layout.layout_logistics_item_layout, expressBean.getList());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(logisticsAdapter);
    }

    @Override
    public void onExpressFailed(String err) {
        hideLoadingDialog();
        ToastUtils.showShort(err);
    }
}
